#!/usr/bin/env python
# coding=utf-8
"""
# @Created on : 2016/06/22 16:07
# @Author     : ldf (ldf@eehello.com)
# @Link       : http://www.eehello.com
# @Version    : 
# 本程序在python2.7下测试通过
"""

#1 - import library
# 导入pygame库，这一步能让你使用库里提供的功能
import pygame
from pygame.locals import *

#2 - initialize the game
# 初始化pygame，设置展示窗口
pygame.init()
width, height = 640, 480
screen = pygame.display.set_mode((width,height))

#3 - load images 加载作为兔子的图片
player = pygame.image.load("resources/images/dude.png")
grass = pygame.image.load("resources/images/grass.png")
castle = pygame.image.load("resources/images/castle.png")


#4 - keep looping through 不停地循环执行接下来的部分
while 1:
    #5 - clear the screen before drawing it again
    # 在给屏幕画任何东西之前用黑色进行填充
    screen.fill(0)
    #6 - draw the screen elements

    for x in range(width/grass.get_width()+1):
        for y in range(height/grass.get_height()+1):
            screen.blit(grass,(x*100,y*100))

    screen.blit(castle,(0,30))
    screen.blit(castle,(0,135))
    screen.blit(castle,(0,240))
    screen.blit(castle,(0,345))

    # 在屏幕的（100，100）坐标出添加你加载的兔子图片
    screen.blit(player,(100,100))

    #7 - update the screen 更新屏幕
    pygame.display.flip()
    #8 - loop through the events
    # 检查一些新的事件，如果有退出命令，则终止程序的执行
    for event in pygame.event.get():
        # check if the event is the X button
        if event.type == pygame.QUIT:
            # if it is quit the game
            pygame.quit()
            exit(0)
